 <template>
    <h1>猜数字游戏</h1>
    <input type="text" placeholder="请输入您猜的数字" v-model="userInput">
    <button @click="check">猜数字</button>
    <h1>您猜的结果是{{userInput}}</h1>
  </template>

  <script setup>
    import { ref } from 'vue'

    let targetNumber = parseInt(Math.random()*100+1);
    console.log("打个小抄:"+targetNumber);

    const userInput = ref('');

    const check = () => {
      const userNumber = Number(userInput.value);

      // 输入验证
      if (isNaN(userNumber) || userInput.value === '') {
        alert("请输入有效的数字");
        return;
      }

      if (userNumber > targetNumber) {
        alert("您猜的数字大了");
      } else if (userNumber < targetNumber) {
        alert("您猜的数字小了");
      } else {
        alert("恭喜您猜对了");
      }
    }
  </script>




<style scoped>

</style>